using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using Engine.SceneControl;
using Engine.SceneControl.BrutalForceWorld;
using Engine.Physic;
using Engine;
using Engine.Cameras;
using Engine.SceneControl.SimpleObject;
using Engine.Physic.PhysicObjects;
using Engine.Material;
using Engine.Modelo;
using Engine.Light;

namespace Etapa1
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        EngineStuff engine;
        ScreenManager manager;
        Scene cena;
        BrutalForceWorld mundo;
        DummyWorld fisico;

        public Game1()
        {
            engine = EngineStuff.CreateAndStartEngine();
            manager = engine.ScreenManager;
            cena = new Scene();
            fisico = new DummyWorld();
            mundo = new BrutalForceWorld();
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {           

            IModelo modelo = new SimpleModel("..\\Content\\Model\\block");
            modelo.LoadModelo(engine.Game.Content);
            ICamera cam = new StaticCamera();
            cam.Position = new Vector3(20, 0, 0);
            cam.Target = new Vector3(0, 0, 0);
            IPhysicObject phisic = new DummyObject();
            ShaderLib slib = engine.GetManagedObject<ShaderLib>("Engine.Material.ShaderLib");
            IMaterial material = new Material(slib.getMaterial(ShaderLib.FLAT));
            //IMaterial material = engine.GetManagedObject<IMaterial>("Engine.Material.XnaMaterial");
            IObject obj = new SimpleObject(material, phisic, modelo, null);
            obj.Position = new Vector3(1,0,0);
            obj.Scale = new Vector3(1, 1, 1);

            DirectionalLight luz = new DirectionalLight();
            luz.AmbientLightColor = new Vector4(0.5f,0.5f,0.5f,0.5f);
            luz.DiffuseLightColor = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
            luz.DiffuseLightDirection = new Vector3(1, 1, 1);
            mundo.AddLight(luz);

            IObject obj2 = new SimpleObject(material, phisic, modelo, null);
            obj.Position = new Vector3(0, 0, 0);
            obj.Scale = new Vector3(1, 50, 50);
            
            mundo.AddCamera(cam);
            mundo.AddObject(obj);
                        
            cena.World = mundo;
            cena.PhysicWorld = fisico;
            manager.AddScreen(cena);
            base.Initialize();
        }

        
        
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            manager.Update(gameTime);

            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            
            manager.Draw(gameTime);
            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}
